<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="报文主题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="theme">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择报文主题"
                v-model="model.theme"
                dict="llbb_param_config,name,code"
                pidValue="1234194297089617900"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报文编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reporttypecode">
              <a-input v-model="model.reporttypecode" placeholder="请输入报文编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reporttypename">
              <a-input v-model="model.reporttypename" placeholder="请输入报文名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="频度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="frequency">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择频度"
                v-model="model.frequency"
                dict="llbb_param_config,name,code"
                pidValue="348523d249be49c68275466beacdcd52"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分片标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjdqpsFlag">
              <j-dict-select-tag type="list" v-model="model.sjdqpsFlag" dictCode="sjdqps_flag" placeholder="请选择分片标识"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报送最大数据量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportNum">
              <a-input-number v-model="model.reportNum" placeholder="请输入报送最大数据量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="补录表编码集" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="buluCodes">
              <JMultiSelectTag placeholder="请选择补录表编码集" v-model="model.buluCodes" dictCode="LLBB_REPORT_FORMS,REPORTTYPENAME,REPORTTYPECODE"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报送SQL" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportSql">
              <a-textarea v-model="model.reportSql" rows="6" placeholder="请输入报送SQL"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: 'LlbbMessageFormsForm',
    components: {
      JDictSelectTag,
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/llbbMessageForms/llbbMessageForms/add",
          edit: "/llbbMessageForms/llbbMessageForms/edit",
          queryById: "/llbbMessageForms/llbbMessageForms/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>